/**
 * ***************************************************************************** Copyright (c) 2003,
 * 2006 Subclipse project and others. All rights reserved. This program and the accompanying
 * materials are made available under the terms of the Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * <p>Contributors: Subclipse project committers - initial API and implementation
 * ****************************************************************************
 */
package org.tigris.subversion.subclipse.ui.actions;

import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.team.ui.history.IHistoryView;
import org.tigris.subversion.subclipse.core.ISVNRemoteResource;
import org.tigris.subversion.subclipse.ui.ISVNUIConstants;
import org.tigris.subversion.subclipse.ui.Policy;

/** Show history for selected remote file */
public class ShowHistoryAction extends SVNAction {

  /*
   * @see SVNAction#executeIAction)
   */
  public void execute(IAction action) throws InterruptedException, InvocationTargetException {
    run(
        new IRunnableWithProgress() {
          public void run(IProgressMonitor monitor) {
            ISVNRemoteResource[] resources = getSelectedRemoteResources();
            if (resources.length == 0) resources = getSelectedRemoteFolders();
            IHistoryView view = (IHistoryView) showView(ISVNUIConstants.HISTORY_VIEW_ID);
            if (view != null) {
              view.showHistoryFor(resources[0]);
            }
          }
        },
        false /* cancelable */,
        PROGRESS_BUSYCURSOR);
  }
  /*
   * @see TeamAction#isEnabled()
   */
  protected boolean isEnabled() {
    ISVNRemoteResource[] resources = getSelectedRemoteResources();
    if (resources.length == 1) return true;
    if (resources.length == 0 && getSelectedRemoteFolders().length == 1) return true;
    return false;
  }
  /** @see org.tigris.subversion.subclipse.ui.actions.SVNAction#getErrorTitle() */
  protected String getErrorTitle() {
    return Policy.bind("ShowHistoryAction.showHistory"); // $NON-NLS-1$
  }

  /*
   * @see org.tigris.subversion.subclipse.ui.actions.ReplaceableIconAction#getImageId()
   */
  protected String getImageId() {
    return ISVNUIConstants.IMG_MENU_SHOWHISTORY;
  }
}
